package com.dianban.controller;

import com.dianban.base.ResultCode;
import com.dianban.base.ResultVo;
import com.dianban.config.redis.RedisUtil;
import com.dianban.entity.*;
import com.dianban.service.*;

import com.dianban.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author wujh
 * @create 2020/1/10
 */
@Api(value = "ApiPaymentController", description = "支付控制器")
@RestController
@RequestMapping(value = "${interfacePath}/payment/")
public class ApiPaymentController extends BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private WxUserService wxUserService;
    @Autowired
    private FacePayStoreOrderService facePayStoreOrderService;
    @Autowired
    private FacePayStoreConsumeLogService facePayStoreConsumeLogService;
    @Autowired
    private StoreGuideService storeGuideService;

    @ApiOperation(notes = "paymentMethods", httpMethod = "GET", value = "获取支付方式列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "screenMac", value = "屏幕Mac", required = true, paramType = "header", dataType = "string"),
            @ApiImplicitParam(name = "shopUserToken", value = "商户用户token", required = true, paramType = "header", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "paymentAmount", value = "支付金额，单位为元，2位小数", required = true, paramType = "query", dataType = "BigDecimal"),
            @ApiImplicitParam(name = "paymentType", value = "支付类型 10 使用套餐  20 门店支付", required = false, paramType = "query", dataType = "string"),
    })
    @RequestMapping(value = "paymentMethods", method = RequestMethod.GET)
    public ResultVo paymentMethods(Long userId,BigDecimal paymentAmount,String paymentType, HttpServletRequest request, HttpServletResponse response) {
        if (userId == null) {
            return ResultVo.error(ResultCode.ERROR, "用户id不能为空");
        }
        User user = userService.findById(userId);
        if (user == null) {
            return ResultVo.error(ResultCode.ERROR, "用户id错误");
        }
        if(paymentAmount == null){
            return ResultVo.error(ResultCode.ERROR, "支付金额不能为空");
        }
       /* Map<String, Object> couponPayment = new HashMap<>();
        couponPayment.put("name", "福利券支付");
        couponPayment.put("method", 20);
        couponPayment.put("balance", user.getCoupon());
        couponPayment.put("coupon", user.getEnergy());
        couponPayment.put("energy", user.getEnergy());
        paymentMethodList.add(couponPayment);*/
       /* Map<String, Object> moneyPayment = new HashMap<>();
        moneyPayment.put("name", "余额支付");
        moneyPayment.put("method", 30);
        moneyPayment.put("balance", user.getMoney());
        moneyPayment.put("money", user.getMoney());
        paymentMethodList.add(moneyPayment);*/
        ShopUser shopUser = UserUtils.getShopUser(request);
       // Long shopUserId = shopUser.getId();
        Long storeId = shopUser.getStoreId();
        List<Map<String, Object>> paymentMethodList = new ArrayList<>();

        if(paymentAmount.compareTo(new BigDecimal("500")) != 0 && paymentAmount.compareTo(new BigDecimal("5000")) != 0){
            Map<String, Object> moneyPayment = new HashMap<>();
            moneyPayment.put("name", "金豆支付");
            moneyPayment.put("method", 40);
            moneyPayment.put("balance", user.getGoldBean());
            moneyPayment.put("goldBean", user.getGoldBean());
            paymentMethodList.add(moneyPayment);
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("paymentMethodList", paymentMethodList);
            return ResultVo.success(resultMap, "成功");
        }
        List<Map<String, Object>> paymentMethodList10 = new ArrayList<>();
        List<Map<String, Object>> paymentMethodList20 = new ArrayList<>();
        Integer verifyCount = 0;
        Map<String, Object> payMethod = null;
        String verifyName = "未购买";
        String curPaymentAmount = null;
        // 10 使用套餐
        Map<String,Object> result = userService.findVerify("10",user,ShoproOrder.goodsId_500,null,"10","500");
        verifyCount = (Integer) result.get("verifyCount");
        payMethod = new HashMap<>();
        payMethod.put("name", "￥500");
        payMethod.put("method", 50);
        payMethod.put("paymentAmount", 0);
        payMethod.put("verifyCount", verifyCount);
        payMethod.put("verifyTitle", "能量舱1次体验");
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            payMethod.put("verifyName", "剩余"+verifyCount+"次");
        }else{
            payMethod.put("verifyName", "未购买");
        }
        paymentMethodList10.add(payMethod);
        result = userService.findVerify("10",user,ShoproOrder.goodsId_5000,null,"10","5000");
        verifyCount = (Integer) result.get("verifyCount");
        payMethod = new HashMap<>();
        payMethod.put("name", "￥5000");
        payMethod.put("method", 51);
        payMethod.put("paymentAmount", 0);
        payMethod.put("verifyCount", result.get("verifyCount"));
        payMethod.put("verifyTitle", "能量舱10次包");
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            payMethod.put("verifyName", "剩余"+verifyCount+"次");
        }else{
            payMethod.put("verifyName", "未购买");
        }
        paymentMethodList10.add(payMethod);
       /* result = userService.findVerify("30",user,ShoproOrder.goodsId_5000,null,"10");
        verifyCount = (Integer) result.get("verifyCount");
        if(verifyCount > 0){
            payMethod = new HashMap<>();
            payMethod.put("name", "免费\n体验");
            payMethod.put("method", 52);
            payMethod.put("paymentAmount", 0);
            payMethod.put("verifyCount", result.get("verifyCount"));
            paymentMethodList10.add(payMethod);
        }*/
        // 20 门店支付
//        curPaymentAmount = "9.9";
//        result = userService.findVerify("40",user,null,null,"20",curPaymentAmount);
//        verifyCount = (Integer) result.get("verifyCount");
//        verifyName = "9.9体验套餐";
//        if(verifyCount > 0){
//            payMethod = new HashMap<>();
//            payMethod.put("useMoney", false);
//            if(verifyCount == 1 || verifyCount > 2 || result.get("canBuy") == null){
//                curPaymentAmount = "0";
//                verifyName = "剩余"+verifyCount+"次";
//            } else {
//                verifyCount = 0;
//                payMethod.put("useMoney", true);
//            }
//            payMethod.put("name", "￥9.9");
//            payMethod.put("method", 60);
//            payMethod.put("paymentAmount", curPaymentAmount);
//            payMethod.put("verifyCount", verifyCount);
//            payMethod.put("verifyTitle", verifyName);
//            paymentMethodList20.add(payMethod);
//        }

        curPaymentAmount = "29.9";
        result = userService.findVerify("40",user,null,null,"20",curPaymentAmount);
        verifyCount = (Integer) result.get("verifyCount");
        verifyName = "29.9体验套餐";
        if(verifyCount > 0){
            payMethod = new HashMap<>();
            payMethod.put("useMoney", false);
            if(verifyCount == 1 || verifyCount > 2 || result.get("canBuy") == null){
                curPaymentAmount = "0";
                verifyName = "剩余"+verifyCount+"次";
            } else {
                verifyCount = 0;
                payMethod.put("useMoney", true);
            }
            payMethod.put("name", "￥29.9");
            payMethod.put("method", 60);
            payMethod.put("paymentAmount", curPaymentAmount);
            payMethod.put("verifyCount", verifyCount);
            payMethod.put("verifyTitle", verifyName);
            paymentMethodList20.add(payMethod);
        }

       curPaymentAmount = "3999";
        result = userService.findVerify("20",user,null,storeId,"20",curPaymentAmount);
        verifyCount = (Integer) result.get("verifyCount");
        verifyName = "未购买";
        curPaymentAmount = "3999";
        payMethod = new HashMap<>();
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            verifyName = "剩余"+verifyCount+"次";
            curPaymentAmount = "0";
        } else {
            payMethod.put("useMoney", true);
        }
        payMethod.put("name", "￥3999");
        payMethod.put("method", 61);
        payMethod.put("paymentAmount", curPaymentAmount);
        payMethod.put("verifyCount", verifyCount);
        payMethod.put("verifyTitle", "能量舱20次包");
        payMethod.put("verifyName", verifyName);
        paymentMethodList20.add(payMethod);

        curPaymentAmount = "5000";
        result = userService.findVerify("20",user,null,storeId,"20",curPaymentAmount);
        verifyCount = (Integer) result.get("verifyCount");
        verifyName = "未购买";
        payMethod = new HashMap<>();
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            verifyName = "剩余"+verifyCount+"次";
            curPaymentAmount = "0";
        } else {
            payMethod.put("useMoney", true);
        }
        payMethod.put("name", "￥5000");
        payMethod.put("method", 62);
        payMethod.put("paymentAmount", curPaymentAmount);
        payMethod.put("verifyCount", verifyCount);
        payMethod.put("verifyTitle", "能量舱10次包");
        payMethod.put("verifyName", verifyName);
        paymentMethodList20.add(payMethod);

        curPaymentAmount = "999";
        result = userService.findVerify("20",user,null,storeId,"20",curPaymentAmount);
        verifyCount = (Integer) result.get("verifyCount");
        verifyName = "未购买";
        payMethod = new HashMap<>();
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            verifyName = "剩余"+verifyCount+"次";
            curPaymentAmount = "0";
        } else {
            payMethod.put("useMoney", true);
        }
        payMethod.put("name", "￥999");
        payMethod.put("method", 63);
        payMethod.put("paymentAmount", curPaymentAmount);
        payMethod.put("verifyCount", verifyCount);
        payMethod.put("verifyTitle", "能量舱3次包");
        payMethod.put("verifyName", verifyName);
        paymentMethodList20.add(payMethod);

        // 再增加一种，如果判断用户是该店的门店老板，增加399,30次包
        if (user.getId().equals(shopUser.getId())) {
            curPaymentAmount = "399";
            result = userService.findVerify("20",user,null,storeId,"20",curPaymentAmount);
            verifyCount = (Integer) result.get("verifyCount");
            verifyName = "未购买";
            payMethod = new HashMap<>();
            payMethod.put("useMoney", false);
            if(verifyCount >0){
                verifyName = "剩余"+verifyCount+"次";
                curPaymentAmount = "0";
            } else {
                payMethod.put("useMoney", true);
            }
            payMethod.put("name", "￥399");
            payMethod.put("method", 64);
            payMethod.put("paymentAmount", curPaymentAmount);
            payMethod.put("verifyCount", verifyCount);
            payMethod.put("verifyTitle", "能量舱30次包");
            payMethod.put("verifyName", verifyName);
            paymentMethodList20.add(payMethod);
        }

        curPaymentAmount = "9999";
        result = userService.findVerify("20",user,null,storeId,"20",curPaymentAmount);
        verifyCount = (Integer) result.get("verifyCount");
        verifyName = "未购买";
        payMethod = new HashMap<>();
        payMethod.put("useMoney", false);
        if(verifyCount >0){
            verifyName = "剩余"+verifyCount+"次";
            curPaymentAmount = "0";
        } else {
            payMethod.put("useMoney", true);
        }
        payMethod.put("name", "￥9999");
        payMethod.put("method", 65);
        payMethod.put("paymentAmount", curPaymentAmount);
        payMethod.put("verifyCount", verifyCount);
        payMethod.put("verifyTitle", "能量舱60次包");
        payMethod.put("verifyName", verifyName);
        paymentMethodList20.add(payMethod);

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("paymentMethodList10", paymentMethodList10);
        resultMap.put("paymentMethodList20", paymentMethodList20);
        return ResultVo.success(resultMap, "成功");
    }

    @ApiOperation(notes = "submit", httpMethod = "POST", value = "支付提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "screenMac", value = "屏幕Mac", required = true, paramType = "header", dataType = "string"),
            @ApiImplicitParam(name = "shopUserToken", value = "商户用户token", required = true, paramType = "header", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "paymentAmount", value = "支付金额，单位为元，2位小数", required = false, paramType = "query", dataType = "BigDecimal"),
            @ApiImplicitParam(name = "payMethod", value = "支付方式", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "payIds", value = "支付ID列表(逗号隔开，需要注意先后顺序)", required = false, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "verifyType", value = "核销类型", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "storeGuideId", value = "美导ID", required = false, paramType = "query", dataType = "int"),

    })
    @RequestMapping(value = "submit", method = RequestMethod.POST)
    public ResultVo submit(Long userId,BigDecimal paymentAmount, Integer payMethod, String payIds,Integer verifyType,Long storeGuideId,HttpServletRequest request, HttpServletResponse response) {
        if (payMethod == null) {
            return ResultVo.error(ResultCode.ERROR, "支付方式不能为空");
        }
        if (userId == null) {
            return ResultVo.error(ResultCode.ERROR, "用户id不能为空");
        }
        User user = userService.findById(userId);
        if (user == null) {
            return ResultVo.error(ResultCode.ERROR, "用户id错误");
        }
        ShopUser shopUser = UserUtils.getShopUser(request);
        Long shopUserId = shopUser.getId();
        Long storeId = shopUser.getStoreId();
        String key = "paymentSubmit:"+userId+storeId+payMethod;
        boolean hasKey = RedisUtil.hasKey(key);
        if (hasKey) {
            return ResultVo.error(ResultCode.ERROR, "支付中，请稍等");
        } else {
            RedisUtil.set(key, 1, 30);
        }
        String orderNumber = facePayStoreOrderService.buildOrderNumber();
        FacePayStoreOrder facePayStoreOrder = new FacePayStoreOrder();
        facePayStoreOrder.setStoreId(storeId);
        facePayStoreOrder.setStoreManagerId(shopUserId);
        facePayStoreOrder.setUserId(userId);
        facePayStoreOrder.setMoney(paymentAmount);
        facePayStoreOrder.setOrderNumber(orderNumber);
        facePayStoreOrder.setPayStatus(10);
        facePayStoreOrder.setCommissionStatus(10);
        facePayStoreOrder.setHasVerifyCount(0);
        facePayStoreOrder.setTakenewHasVerifyCount(0);
        if(storeGuideId != null){
            StoreGuide storeGuide = storeGuideService.findById(storeGuideId);
            if(storeGuide == null){
                return ResultVo.error(ResultCode.ERROR, "美导ID错误");
            }
            facePayStoreOrder.setGuideUserId(storeGuide.getUserId());
        }
        FacePayStoreConsumeLog facePayStoreConsumeLog = new FacePayStoreConsumeLog();
        facePayStoreConsumeLog.setStoreId(storeId);
        facePayStoreConsumeLog.setUserId(userId);
        facePayStoreConsumeLog.setMoney(paymentAmount);
        if (payMethod == 20) {
            if (paymentAmount == null) {
                return ResultVo.error(ResultCode.ERROR, "支付金额不能为空");
            }
            BigDecimal coupon = user.getCoupon();
            if (coupon == null || coupon.compareTo(paymentAmount) < 0) {
                return ResultVo.error(ResultCode.ERROR420);
            }
            return userService.updateCoupon(paymentAmount.negate(),paymentAmount.negate(),userId,shopUserId);
        }else if(payMethod == 30){
            BigDecimal money = user.getMoney();
            if (money == null || money.compareTo(paymentAmount) < 0) {
                return ResultVo.error(ResultCode.ERROR422);
            }
            return userService.updateMoney(paymentAmount.negate(),userId,shopUserId);
        }else if(payMethod == 40){
            if (paymentAmount == null) {
                return ResultVo.error(ResultCode.ERROR, "支付金额不能为空");
            }
            if (paymentAmount.compareTo(BigDecimal.ZERO) <= 0) {
                return ResultVo.error(ResultCode.ERROR, "支付金额不能小于等于零");
            }
            BigDecimal goldBean = user.getGoldBean();
            if (goldBean == null || goldBean.compareTo(paymentAmount) < 0) {
                return ResultVo.error(ResultCode.ERROR423);
            }
            return userService.updateGoldBean(paymentAmount.negate(),userId,shopUserId);
        }else if(payMethod == 50){
            Map<String,Object> verifyResult = userService.findVerify("10",user,ShoproOrder.goodsId_500,null,"10","500");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                return ResultVo.error(ResultCode.ERROR, "￥500已使用完");
            }
            facePayStoreConsumeLog.setType("10");
            facePayStoreConsumeLog.setOnlineOrderId(orderIdList.get(0));
            facePayStoreConsumeLog.setMemo("线上500套餐核销");
            return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
        }else if(payMethod == 51){
            Map<String,Object> verifyResult = userService.findVerify("10",user,ShoproOrder.goodsId_5000,null,"10","5000");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                return ResultVo.error(ResultCode.ERROR, "￥5000已使用完");
            }
            facePayStoreConsumeLog.setType("10");
            facePayStoreConsumeLog.setOnlineOrderId(orderIdList.get(0));
            facePayStoreConsumeLog.setMemo("线上5000套餐核销");
            return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
        }else if(payMethod == 52){
            Map<String,Object> verifyResult = userService.findVerify("30",user,ShoproOrder.goodsId_5000,null,"10","0");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                return ResultVo.error(ResultCode.ERROR, "免费体验已使用完");
            }
            facePayStoreConsumeLog.setType("30");
            facePayStoreConsumeLog.setOnlineOrderId(orderIdList.get(0));
            facePayStoreConsumeLog.setMemo("线上带新体验核销");
            return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
        }else if(payMethod == 60){
//            Map<String,Object> verifyResult = userService.findVerify("40",user,null,storeId,"20","9.9");
//            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
//            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
//            if(verifyCount == 1){
//                facePayStoreConsumeLog.setType("40");
//                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
//                facePayStoreConsumeLog.setMemo("线下9.9体验套餐核销");
//                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
//            }else{
//                facePayStoreOrder.setMemo("9.9体验套餐");
//                facePayStoreOrder.setPayType( "40");
//                facePayStoreOrder.setCanVerifyCount(1);
//                facePayStoreOrder.setTakenewVerifyCount(0);
//                facePayStoreOrderService.insert(facePayStoreOrder);
//                Map<String,Object> resultMap = new HashMap<>();
//                resultMap.put("out_trade_no", orderNumber);
//                return ResultVo.success(resultMap, "成功");
//            }
            Map<String,Object> verifyResult = userService.findVerify("40",user,null,storeId,"20","29.9");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 1){
                facePayStoreConsumeLog.setType("40");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下29.9体验套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }else{
                facePayStoreOrder.setMemo("29.9体验套餐");
                facePayStoreOrder.setPayType( "40");
                facePayStoreOrder.setCanVerifyCount(1);
                facePayStoreOrder.setTakenewVerifyCount(0);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }
        }else if(payMethod == 61){
            Map<String,Object> verifyResult = userService.findVerify("20",user,null,storeId,"20","3999");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                facePayStoreOrder.setMemo("线下充值3999元");
                facePayStoreOrder.setPayType( "20");
                facePayStoreOrder.setCanVerifyCount(20);
                facePayStoreOrder.setTakenewVerifyCount(5);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }else{
                facePayStoreConsumeLog.setType("20");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下3999套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }
        }else if(payMethod == 62){
            Map<String,Object> verifyResult = userService.findVerify("20",user,null,storeId,"20","5000");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                facePayStoreOrder.setMemo("线下充值5000元");
                facePayStoreOrder.setPayType( "20");
                facePayStoreOrder.setCanVerifyCount(10);
                facePayStoreOrder.setTakenewVerifyCount(5);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }else{
                facePayStoreConsumeLog.setType("20");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下5000套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }
        }else if(payMethod == 63){
            Map<String,Object> verifyResult = userService.findVerify("20",user,null,storeId,"20","999");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                facePayStoreOrder.setMemo("线下充值999元");
                facePayStoreOrder.setPayType( "20");
                facePayStoreOrder.setCanVerifyCount(3);
                facePayStoreOrder.setTakenewVerifyCount(0);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }else{
                facePayStoreConsumeLog.setType("20");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下999套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }
        }else if(payMethod == 64){
            Map<String,Object> verifyResult = userService.findVerify("20",user,null,storeId,"20","399");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                facePayStoreOrder.setMemo("线下充值399元");
                facePayStoreOrder.setPayType( "20");
                facePayStoreOrder.setCanVerifyCount(30);
                facePayStoreOrder.setTakenewVerifyCount(0);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }else{
                facePayStoreConsumeLog.setType("20");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下399套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }
        }else if(payMethod == 65){
            Map<String,Object> verifyResult = userService.findVerify("20",user,null,storeId,"20","9999");
            Integer verifyCount = (Integer) verifyResult.get("verifyCount");
            List<Long> orderIdList = (List<Long>)verifyResult.get("orderIdList");
            if(verifyCount == 0){
                facePayStoreOrder.setMemo("线下充值9999元");
                facePayStoreOrder.setPayType( "20");
                facePayStoreOrder.setCanVerifyCount(60);
                facePayStoreOrder.setTakenewVerifyCount(0);
                facePayStoreOrderService.insert(facePayStoreOrder);
                Map<String,Object> resultMap = new HashMap<>();
                resultMap.put("out_trade_no", orderNumber);
                return ResultVo.success(resultMap, "成功");
            }else{
                facePayStoreConsumeLog.setType("20");
                facePayStoreConsumeLog.setOfflineOrderId(orderIdList.get(0));
                facePayStoreConsumeLog.setMemo("线下9999套餐核销");
                return  facePayStoreConsumeLogService.verify(facePayStoreConsumeLog,shopUserId);
            }
        }else {
            return ResultVo.error(ResultCode.ERROR, "支付方式不存在,请重新选择支付方式");
        }
    }

}
